package com.ifengchao.util.sina;

import java.util.Map;

import org.apache.log4j.Logger;

public class HttpParamUtil {
	private static final Logger logger = Logger.getLogger( HttpParamUtil.class);
	/**
	 * Map的数据转换成POST请求参数的格式。 name1=value1&name2=value2 的形式。
	 */
	public static String getHttpParameterFromMap(Map<String, String> map) {
		StringBuffer stringBuffer = new StringBuffer();

		for (Map.Entry<String, String> entry : map.entrySet()) {
			try {
				stringBuffer.append(entry.getKey()).append("=")
						.append(entry.getValue())
						.append("&");

			} catch (Exception e) {
				logger.error("转换POST请求参数格式出现异常！" + e);
			}
		}
		stringBuffer.deleteCharAt(stringBuffer.length() - 1);
		
		logger.debug("转换后的POST请求参数串：" + stringBuffer.toString());
		return stringBuffer.toString();
	}

}
